home *** CD-ROM | disk | FTP | other *** search
/ STraTOS 1997 April & May / STraTOS 1 - 1997 April & May.iso / CD01 / PRGMANIA / BFED.10 / DIALOG.C < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-27  |  12.5 KB  |  524 lines

  1. /*
  2.     file: dialog.c
  3.     utility: Manage forms in windows
  4.     date: 1996
  5.     author: C. Moreau
  6.     modifications:
  7.         17 aug 96: C. Moreau: Suppressed separate title name for
  8.          forms dialogs.
  9.         23 jan 97: C. Moreau: Changed all functions names to have
  10.             window_ in firs.
  11.      comments: 
  12. */
  13.  
  14. #include <ctype.h>
  15. #include <stdlib.h>
  16. #include <string.h>
  17.  
  18. #ifdef __PUREC__ 
  19. #include <aes.h>
  20. #include <tos.h>
  21. #include <vdi.h>
  22. #include <compend.h>
  23. #else
  24. #include <aesbind.h>
  25. #include <tosbind.h>
  26. #include <vdibind.h>
  27. #endif
  28.  
  29. #include "e:\proging\c\libs\malib\alert.h"
  30. #include "config.h"
  31. #include "dialog.h"
  32. #include "events.h"
  33. #include "init.h"
  34. #include "keys.h"
  35. #include "search.h"
  36. #include "wind.h"
  37.  
  38. #include "bfed_rsc.h"                    /* resource */
  39.  
  40. /*
  41.     Globals vars
  42. */
  43. OBJECT *dinfo;
  44. OBJECT *dsearch;
  45. OBJECT *ddisk;
  46. OBJECT *dprint;
  47. OBJECT *dpos;
  48.  
  49. /*
  50.     Locals vars
  51. */
  52. static char dr_str[32] = {""};    /* for drive space function */
  53.  
  54. /*
  55.     Locals functions
  56. */
  57. static void dialog_print_init(void);
  58. static void dialog_disk_init(void);     
  59. static void dialog_info_init(void);
  60. static void dialog_search_init(void);     
  61. static void one_dialog(windowptr thewin, GRECT *r1);
  62. static windowptr new_dialog(int thekind);
  63.  
  64. /*
  65.     name: open_dialog
  66.     utility: make or raise a specific dialog
  67.     comment: (as open_window and new_window)
  68.     parameters:
  69.         int dialog_nb: number of the dialog
  70.     return: none.
  71.     date: 1996
  72.     author: C.Moreau
  73.     modifications:
  74. */
  75. void open_dialog(int dialog_nb)
  76. {
  77.     windowptr thewin=firstwindow;
  78.     OBJECT *dialog_addr;
  79.  
  80.     rsrc_gaddr(R_TREE, dialog_nb, &dialog_addr);
  81.     
  82.         /* look if the form is already opened */
  83.     while(thewin)
  84.     {
  85.         if (thewin->form == dialog_addr)
  86.         {
  87.             window_put_top(thewin);
  88.             return;
  89.         }
  90.         thewin = thewin->next;
  91.     }
  92.  
  93.         /* There is no form */
  94.     thewin = new_dialog(dialog_nb);
  95.  
  96.     if (thewin)
  97.         window_open(thewin);
  98.     else
  99.         window_resources_dispose(thewin);
  100. }
  101.  
  102. /*
  103.     name: new_dialog
  104.     utility: create & draw a new dialog.
  105.     comment:
  106.                  1.)  create the window.
  107.                 2.)  draw the window with the wind_open()
  108.                 3.)  create and setup the window record.
  109.                 Adapted from new_window function.
  110.         This is a Copy of new_window adapted for a dialog.
  111.         Max size is the desktop: Doesn't have a fuller button.
  112.         Title of the dialog is in index # 1 in the Object.
  113.     parameters:
  114.         int dialog_nb: index of dialog.
  115.         *OBJECT dialog_addr: address of the form.
  116.     return: windowptr: ptr on dialog window
  117.     date: 12 may 96
  118.     author: C. Moreau
  119.     modifications: 
  120. */
  121. static windowptr new_dialog(int dialog_nb)
  122. {
  123.     int handle;                    /* window handle */
  124.     int x,y,w,h;                /* window sizes */
  125.     int thekind = NAME|CLOSER|MOVER;    /* window items */
  126.     windowptr thewin=NULL;    /* window ptr */
  127.     OBJECT *dialog_addr;        /* object ptr */
  128.  
  129.     rsrc_gaddr(R_TREE, dialog_nb, &dialog_addr);
  130.  
  131.         /*    Create the information for the window.
  132.             Max size is the form. */
  133.     wind_calc(WC_BORDER, thekind,                                        \
  134.                 dialog_addr->ob_x, dialog_addr->ob_y,                \
  135.                 dialog_addr->ob_width, dialog_addr->ob_height,    \
  136.                 &x, &y, &w, &h);
  137.     
  138.     handle = wind_create(thekind, x, y, w, h);
  139.     if (handle < 0)
  140.         rsc_alert(NOWIND_3);
  141.     else
  142.     {
  143.             /*    Allocate space for window record. */
  144.         thewin = (windowptr) malloc(sizeof(windowrec));
  145.         if (!thewin)
  146.         {
  147.             wind_delete(handle); /* delete the window created above  */
  148.             rsc_alert(NOMEM_5);
  149.         }
  150.         else
  151.         {     
  152.                 /*    Initialize window data structure. */
  153.             thewin->next            = NULL;
  154.             thewin->handle            = handle;
  155.             thewin->kind            = thekind;
  156.             thewin->fullsize        = TRUE;
  157.             thewin->graf.handle     = -1;
  158.             thewin->updateproc         = one_dialog;
  159.             thewin->headptr              = NULL;
  160.             thewin->startmark       = 1;
  161.             thewin->endmark              = 0;
  162.             thewin->markson         = 0;
  163.             thewin->xcur              = 0;
  164.             thewin->ycur              = 0;
  165.             thewin->topchar              = 0;
  166.             thewin->flen              = 0;
  167.             thewin->position          = 0;
  168.             thewin->vslidepos       = 0;
  169.             thewin->icount              = 0;
  170.             thewin->changed              = FALSE;    
  171.             thewin->prot              = TRUE;
  172.             thewin->form             = dialog_addr;
  173.     
  174.                 /* 1st object contain the dialog title */
  175.             wind_set(handle, WF_NAME, 
  176.                     dialog_addr[1].ob_spec.free_string, 0, 0);
  177.     
  178.             insertwindowptr(thewin);
  179.         }
  180.     }
  181.     
  182.     return(thewin);
  183. }
  184.  
  185. /*
  186.     name: one_dialog
  187.     utility: do the redraw of a dialog.
  188.     comment: 
  189.     parameters:
  190.         windowptr thewin: pointer on the window dialog struct.
  191.         GRECT rect: rectangle to redraw
  192.     return: none
  193.     date: 12 may 96
  194.     author: C.Moreau
  195.     modifications: 
  196. */
  197. static void one_dialog(windowptr thewin, GRECT *rect)
  198. {
  199.     objc_draw(thewin->form, 0, MAX_DEPTH,    \
  200.                  rect->g_x, rect->g_y,         \
  201.                  rect->g_w, rect->g_h);                   
  202. }
  203.  
  204. /*
  205.     name: init_dialog
  206.     utility: initialise vars of dialog.c module
  207.     comment: 
  208.     parameters:none
  209.     return: none
  210.     date: 1995
  211.     author: C.Moreau
  212.     modifications: 
  213. */
  214. void init_dialog(void)
  215. {
  216.     int dummy;
  217.     
  218.         /* Initialise the forms */
  219.     rsrc_gaddr(R_TREE, DSEARCH, &dsearch);
  220.     rsrc_gaddr(R_TREE, DINFO, &dinfo);
  221.     rsrc_gaddr(R_TREE, DDISK, &ddisk);
  222.     rsrc_gaddr(R_TREE, DPRINT, &dprint);
  223.     rsrc_gaddr(R_TREE, DPOS, &dpos);
  224.     
  225.         /* Center forms */
  226.     form_center(dsearch, &dummy, &dummy, &dummy, &dummy);
  227.     form_center(dinfo, &dummy, &dummy, &dummy, &dummy);
  228.     form_center(ddisk, &dummy, &dummy, &dummy, &dummy);
  229.     form_center(dprint, &dummy, &dummy, &dummy, &dummy);
  230.     form_center(dpos, &dummy, &dummy, &dummy, &dummy);
  231.  
  232.         /* init forms */
  233.     dialog_search_init();
  234.     dialog_info_init();
  235.     dialog_print_init();
  236.     dialog_disk_init();
  237. }
  238.  
  239. /*
  240.     name: dialog_search_init
  241.     utility: Set up search Dialog
  242.     comment: 
  243.     parameters:none
  244.     return: none
  245.     date: 1996
  246.     author: C.Moreau
  247.     modifications: 
  248. */
  249. static void dialog_search_init(void)
  250. {
  251.         /* init search/replace string */
  252.     dsearch[SSTRING].ob_spec.tedinfo->te_ptext = s_str;
  253.     dsearch[SSTRING].ob_spec.tedinfo->te_txtlen = MAX_SEARCH;
  254.     dsearch[RSTRING].ob_spec.tedinfo->te_ptext = r_str;
  255.     dsearch[RSTRING].ob_spec.tedinfo->te_txtlen = MAX_SEARCH;
  256. }
  257.  
  258. /*
  259.     name: dialog_search_exec
  260.     utility: Actions on a dialog
  261.     comment: Manage actions done on dialogs
  262.         called only from button.c module.
  263.         Exec the command associated to the form.
  264.     parameters: none
  265.     return: none
  266.     date: 1996
  267.     author: C. Moreau
  268.     modifications: 
  269. */
  270. void dialog_search_exec(void)
  271. {
  272.     if ( objet == CANCEL1 || objet == RBUT || objet == SBUT \
  273.         || objet == NBUT )
  274.     {
  275.         objc_change(dsearch, objet, 0, dsearch->ob_x,    \
  276.                     dsearch->ob_y, dsearch->ob_width,        \
  277.                     dsearch->ob_height,    NORMAL, REDRAW);
  278.         if (objet != CANCEL1)
  279.             find0(objet);
  280.         else
  281.             window_dispose(thefrontwin);    /* close window */
  282.     }
  283.     else if ( objet == RALL || objet == RVER            \
  284.             || objet == RCUTBUF || objet == SCUTBUF    \
  285.             || objet == RHEXA || objet == SHEXA )
  286.     {
  287.         if (dsearch[objet].ob_state == SELECTED)
  288.             objc_change(dsearch, objet, 0, dsearch->ob_x,    \
  289.                         dsearch->ob_y, dsearch->ob_width,        \
  290.                         dsearch->ob_height,    NORMAL, REDRAW);
  291.         else
  292.             objc_change(dsearch, objet, 0, dsearch->ob_x,    \
  293.                         dsearch->ob_y, dsearch->ob_width,        \
  294.                         dsearch->ob_height,    SELECTED, REDRAW);                
  295.     }
  296. }
  297.  
  298. /*
  299.     name: dialog_info_init
  300.     utility: Set up info Dialog
  301.     comment: 
  302.     parameters:none
  303.     return: none
  304.     date: 1996
  305.     author: C.Moreau
  306.     modifications: 
  307. */
  308. static void dialog_info_init(void)
  309. {
  310.         /*put version number & proc type */
  311. #if defined(M68K)
  312.     strcpy(dinfo[DINFO_VERSION].ob_spec.tedinfo->te_ptext, "30+82");
  313. #elif defined(M68030)
  314.         strcpy(dinfo[DINFO_VERSION].ob_spec.tedinfo->te_ptext, "68030");
  315. #elif defined(M68000)
  316.         strcpy(dinfo[DINFO_VERSION].ob_spec.tedinfo->te_ptext, "68000");
  317. #endif
  318.     strcat(dinfo[DINFO_VERSION].ob_spec.tedinfo->te_ptext, VERSION);
  319.     strcat(dinfo[DINFO_VERSION].ob_spec.tedinfo->te_ptext, __DATE__);
  320. }
  321.  
  322. /*
  323.     name: dialog_disk_init
  324.     utility: Set up disk Dialog
  325.     comment: 
  326.         called from menu.c.
  327.         Initialise the form: set the drive button to
  328.         the right config (nb of disk).
  329.         Note that we suppose that the form in the ressource
  330.         contains disabled disk buttons. It put them to normal
  331.         if the drive exist.
  332.     parameters:none
  333.     return: none
  334.     date: 1996
  335.     author: C.Moreau
  336.     modifications: 
  337. */
  338. #define NB_DISK    16
  339. static void dialog_disk_init(void)
  340. {
  341.     unsigned long drvs = Drvmap();
  342.     int    dr;
  343.     const int drarray[NB_DISK] = {AA,BB,CC,DD,EE,FF,GG,HH,II,JJ,KK,LL,MM,NN,OO,PP};
  344.  
  345.         /* init disk size info string */
  346.     ddisk[DRSTR1].ob_spec.tedinfo->te_ptext = dr_str;
  347.         
  348.         /* Enable only existing drives */
  349.     for (dr = 1; dr <= NB_DISK; dr++, drvs >>= 1)
  350.         if(drvs & 0x001)
  351.             objc_change(ddisk, drarray[dr-1], 0,    \
  352.                 ddisk->ob_x, ddisk->ob_y,            \
  353.                   ddisk->ob_width, ddisk->ob_height,    \
  354.                   NORMAL, NO_REDRAW);
  355. }
  356.  
  357.  
  358. /*
  359.     name: dialog_disk_exec
  360.     utility: Actions on a dialog
  361.     comment: Manage actions done on dialogs
  362.     parameters: none
  363.     return: none
  364.     date: 1996
  365.     author: C. Moreau
  366.     modifications: 
  367. */
  368. void dialog_disk_exec(void)
  369. {
  370.     int idr = 0, dr;
  371.     const int drarray[NB_DISK] = {AA,BB,CC,DD,EE,FF,GG,HH,II,JJ,KK,LL,MM,NN,OO,PP};
  372.     DISKINFO myinfo;
  373.         
  374.         /* find the choosen drive */
  375.     for(dr = 1; dr <= NB_DISK; dr++)
  376.         if(drarray[dr-1] == objet)
  377.             idr = dr;
  378.  
  379.     graf_mouse(BUSYBEE, 0);
  380.     Dfree(&myinfo, idr);
  381.     graf_mouse(ARROW, 0);    
  382.  
  383.     {
  384.         char *string;
  385.  
  386.         rsrc_gaddr(R_STRING, S_FREEBYTE, &string);
  387.         sprintf(dr_str, string,                                        \
  388.                 myinfo.b_free*myinfo.b_clsiz*myinfo.b_secsiz,    \
  389.                 'A' + (idr-1));
  390.     }
  391.     
  392.     objc_draw(ddisk, DRBOX, 1,                \
  393.                 ddisk->ob_x, ddisk->ob_y,    \
  394.                 ddisk->ob_width, ddisk->ob_height);
  395. }
  396.  
  397. /******************PRINT**************************/
  398. /*
  399.     name: dialog_print_init
  400.     utility: Set up printer Dialog
  401.     comment: 
  402.     parameters:none
  403.     return: none
  404.     date: 1996
  405.     author: C.Moreau
  406.     modifications: 
  407. */
  408. static void dialog_print_init(void)
  409. {
  410.              /* enable/disable Gdos buttons */
  411.     if (vq_gdos)    /* Bugged fn in Pure C V 1.0 should return -2 if not GDOS */
  412.     {
  413.         const int rsc_array[10]={ PRINT_GDOS, PRINT_ID_PLUS,PRINT_ID_MOINS,
  414.                             PRINT_ID, PRINT_NAME,PRINT_FN_PLUS,
  415.                             PRINT_FN_MOINS,FONT_ID,FONT_NAME, -1};
  416.         register int i=0;
  417.         
  418.         while (rsc_array[i] != -1)
  419.         {
  420.             objc_change(dprint, rsc_array[i], 0, dprint->ob_x, dprint->ob_y,
  421.                         dprint->ob_width, dprint->ob_height, DISABLED, NO_REDRAW); 
  422.             i++;
  423.         }
  424.     }
  425.  
  426.                 /* Find default Device & Fnt */
  427.             /****************/
  428. }
  429.  
  430. /*
  431.     name: dialog_print_exec
  432.     utility: Actions on a dialog
  433.     comment: Manage actions done on dialogs
  434.     parameters: none
  435.     return: none
  436.     date: 1996
  437.     author: C. Moreau
  438.     modifications: 
  439. */
  440. void dialog_print_exec(void)
  441. {
  442.     if ( objet == PRINT_OK || objet == PRINT_ANN                \
  443.         || objet == PRINT_ID_PLUS || objet == PRINT_ID_MOINS    \
  444.         || objet == PRINT_FN_PLUS || objet == PRINT_FN_MOINS )
  445.     {
  446.         objc_change(dprint, objet, 0, dprint->ob_x,    \
  447.                     dprint->ob_y, dprint->ob_width,    \
  448.                     dprint->ob_height, NORMAL, REDRAW); 
  449.         if ( objet == PRINT_OK || objet == PRINT_ANN )
  450.             window_dispose(thefrontwin);    /* close window */
  451.     }
  452.     else if (objet == PRINT_GDOS)
  453.     {
  454.         if (vq_gdos != 0)        /* Warning this is an other bugged function of Pure
  455.                                     it should return -2 if no Gdos */
  456.             objc_change(dprint, PRINT_GDOS, 0, dprint->ob_x,    \
  457.                         dprint->ob_y, dprint->ob_width,            \
  458.                         dprint->ob_height, NORMAL, REDRAW); 
  459.     }
  460. }
  461.  
  462. /****************** POS **************************/
  463. /*
  464.     name: dialog_pos_exec
  465.     utility: Take params for going to a position
  466.     comment: Manage actions done on a dialog
  467.     parameters: none
  468.     return: none
  469.     date: 1996
  470.     author: C. Moreau
  471.     modifications: 
  472. */
  473. void dialog_pos_exec(void)
  474. {
  475.     const windowptr theformwin=thefrontwin;
  476.  
  477.     if (objet == GO_POS_OK)
  478.     {
  479.         long position;
  480.         windowptr theworkwin = find_workwind();
  481.  
  482.         objc_change(dpos, GO_POS_OK, 0,    dpos->ob_x,    \
  483.                 dpos->ob_y, dpos->ob_width,            \
  484.                 dpos->ob_height, NORMAL, REDRAW); 
  485.     
  486.             /* put cursor at position */
  487.         if (dpos[GO_POS_HEXA].ob_state == SELECTED)
  488.         {
  489.             char string[12]="0x";
  490.             register int idx=0;
  491.             
  492.             strcat(string, dpos[GO_POS_IDX].ob_spec.tedinfo->te_ptext);
  493.  
  494.                 /* transform in Upper case */
  495.             while (string[idx])
  496.             {
  497.                 string[idx] = toupper(string[idx]);
  498.                 idx ++;
  499.             }    
  500.             
  501.             position = strtoul(string, NULL, 16);    /* take New position from string */            
  502.         }
  503.         else
  504.         {                        
  505.             position = strtoul(dpos[GO_POS_IDX].ob_spec.tedinfo->te_ptext, NULL,    10);                     
  506.         }
  507.  
  508.         if (position <= theworkwin->flen)
  509.         {
  510.             theworkwin->position = position;
  511.             check_scroll(theworkwin);
  512.             window_dispose(theformwin);                
  513.         }
  514.         else
  515.             rsc_alert(WRONG_POS);
  516.     }
  517.     else if (objet == GO_POS_ANN)
  518.     {
  519.         objc_change(dpos, objet, 0, dpos->ob_x,        \
  520.                     dpos->ob_y, dpos->ob_width,        \
  521.                     dpos->ob_height, NORMAL, REDRAW); 
  522.         window_dispose(theformwin);                
  523.     }
  524. }